﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Consultas.aspx.cs" Inherits=" RzCorportativo.Views.Consulta.Consultas" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="LeftContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        $(function () {
            $("div[id*='aprovar']").hide();
        });
        function FinalizarAtendimento(consultaId, item) {
            $("div[id*='aprovar']").dialog({
                modal: true,
                width: 300,
                height: 200,
                buttons: {
                    "sim": function () {
                        Finalizar({
                            consultaId: consultaId,
                            aprovado: true,
                            item: item
                        });
                    },
                    "não": function () {
                        Finalizar({
                            consultaId: consultaId,
                            aprovado: false,
                            item: item
                        });
                    }
                },
                open: function (event, ui) {
                    $(".ui-dialog-buttonset").find("button").attr("class", "btn btn-primary");
                }
            });
        }
        function Finalizar(objeto) {
            $.ajax({
                url: eS.UrlPadrao + "Views/Consulta/Consultas.aspx/FinalizarConsulta",
                type: "post",
                data: "{ consultaId: " + objeto.consultaId + ", atendida:" + objeto.aprovado + "}",
                dataType: "json",
                contentType: 'application/json; charset=utf-8',
                success: function (e) {
                    if (e.d && e.d.indexOf("!") == 0) {
                        alert(e.d.substr(1, e.d.length));
                        return;
                    }
                    if (objeto.aprovado)
                        $("a[id*='lnkResolve" + objeto.consultaId + "']").parent().html("<span>Atendida</span>");
                    else
                        $("a[id*='lnkResolve" + objeto.consultaId + "']").parent().html("<span>Não atendida</span>");
                    $("div[id*='aprovar']").dialog("close");
                },
                error: function (e) {
                    if (e.responseText)
                        alert(e.responseText);
                    else
                        alert(e.d);
                }
            });
        }
    </script>
    <h1>
        Consultas
    </h1>
    <hr />
    <div class="controls controls-row">
        <asp:TextBox runat="server" ID="Nome" placeholder="Nome" />
        <asp:TextBox runat="server" ID="CPF" mask="cpf" placeholder="CPF" />
    </div>
    <div class="controls controls-row">
        <asp:TextBox runat="server" ID="NomeMedico" placeholder="Médico" />
        <asp:DropDownList runat="server" ID="Especialidade" Width="265">
        </asp:DropDownList>
    </div>
    <div class="controls controls-row">
        <asp:DropDownList runat="server" ID="Status" Width="265">
            <asp:ListItem Text="Status" Value="0" Selected="True" />
            <asp:ListItem Text="Atendida" Value="1" />
            <asp:ListItem Text="Não Atedida" Value="2" />
        </asp:DropDownList>
        <asp:TextBox runat="server" ID="Data" date="true" mask="calendar" placeholder="Data" />
    </div>
    <div class="controls controls-row">
        <asp:TextBox runat="server" ID="txtHrI" clock="true" placeholder="Hora de Entrada" />
        <asp:TextBox runat="server" ID="txtHrS" clock="true" placeholder="Hora de Saída" />
    </div>
    <%--<table border="0" cellpadding="0" cellspacing="" style="width: 100%">
        <tr>
            <td class="field">
                Paciente:
            </td>
            <td class="field2">
            </td>
            <td class="field">
                CPF:
            </td>
            <td class="field2">
            </td>
        </tr>
        <tr>
            <td class="field">
                Medico:
            </td>
            <td class="field2">
            </td>
            <td class="field">
                Especialidade:
            </td>
            <td class="field2">
            </td>
        </tr>
        <tr>
            <td class="field">
                Data:
            </td>
            <td class="field2">
            </td>
            <td class="field">
                Status:
            </td>
            <td class="field2">
            </td>
        </tr>
        <tr>
            <td class="field">
                Hora de Entrada:
            </td>
            <td class="field2">
            </td>
            <td class="field">
                Hora de Saída:
            </td>
            <td class="field2">
            </td>
        </tr>
    </table>--%>
    <br />
    <asp:Button Text="buscar" ID="buscar" runat="server" OnClick="buscar_Click" CssClass="btn" />
    <div style="min-width: 800px; margin-top: 30px" class="grid">
        <asp:GridView runat="server" AutoGenerateColumns="false" ID="ListaConsulta" AlternatingRowStyle-CssClass="gridrow_alternate"
            RowStyle-CssClass="gridrow" CssClass="table-hover" PageSize="5" AllowPaging="true"
            OnPageIndexChanging="ListaConsulta_PageIndexChanging">
            <EmptyDataTemplate>
                <strong>Não foram encontrados consultas para os filtros selecionados</strong>
            </EmptyDataTemplate>
            <Columns>
                <asp:BoundField DataField="DateConsulta" HeaderText="Data" DataFormatString="{0: dd/MM/yyyy}" />
                <asp:BoundField DataField="HoraEntrada" HeaderText="Entrada" DataFormatString="{0:T}" />
                <asp:BoundField DataField="HoraSaida" HeaderText="Saída" DataFormatString="{0:T}" />
                <asp:TemplateField HeaderText="Paciente">
                    <ItemTemplate>
                        <%# this.GetItem(Container.DataItem).Paciente.Nome%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Medico">
                    <ItemTemplate>
                        <%# this.GetItem(Container.DataItem).Medico.Pessoa.Nome%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Geral">
                    <ItemTemplate>
                        <%# this.GetHtml(Container.DataItem)%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Status" Visible="false">
                    <ItemTemplate>
                        <%--<%# this.GetHtmlAtendido(Container.DataItem)%>--%>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <br />
        <br />
    </div>
    <div id="aprovar" title="Status da Consulta">
        <div>
            Esta consulta foi realizada?
        </div>
    </div>
</asp:Content>
